import os
import os.path

# qrc文件所在位置
dir = "../client/src"


# 列出目录下所有qrc文件
def listQrcFile():
    list = []
    files = os.listdir(dir)
    for filename in files:
        # print(dir + os.sep+ f)
        # print(filename)
        if os.path.splitext(filename)[1] == ".qrc":
            list.append(filename)
    return list


# 把扩展名为.qrc的文件改为.py
def transPyFile(filename):
    return os.path.splitext(filename)[0] + "_rc.py"


# 调用系统命令把.qrc文件换为.py文件
def runMain():
    list = listQrcFile()
    for qrcfile in list:
        pyfile = transPyFile(qrcfile)
        cmd = 'pyrcc5 -o {pyfile} {qrcfile}'.format(pyfile=os.path.join(dir, pyfile), qrcfile=os.path.join(dir, qrcfile))
        # print(cmd)
        os.system(cmd)


# 主程序
if __name__ == "__main__":
    runMain()
